package com.jw.xzg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jw.xzg.R;
import com.jw.xzg.model.FriendItem;

import java.util.List;

/**
 * Created by admin on 2017/4/13.
 */

public class FriendAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<FriendItem> mData;

    public FriendAdapter(Context context) {
        this.mInflater = LayoutInflater.from(context);
    }

    public List<FriendItem> getmData() {
        return mData;
    }

    public void setmData(List<FriendItem> mData) {
        this.mData = mData;
    }

    @Override
    public int getCount() { //数据分页
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.friend_item_view, null);
            holder = new ViewHolder();
                /*得到各个控件的对象*/
            holder.daishu = (TextView) convertView.findViewById(R.id.friend_item_daishu);
            holder.nick = (TextView) convertView.findViewById(R.id.friend_item_nick);
            holder.jingyin =(TextView)convertView.findViewById(R.id.friend_item_jingyin); // to ItemButton

            convertView.setTag(holder); //绑定ViewHolder对象
        }
        else {
            holder = (ViewHolder) convertView.getTag(); //取出ViewHolder对象
        }
           /*设置TextView显示的内容，即我们存放在动态数组中的数据*/
            FriendItem item = (FriendItem) getItem(position);
            holder.daishu.setText(String.valueOf(item.getDaishu()));
            holder.nick.setText(item.getNickName());
            holder.jingyin.setText(item.getIsjingyin());





        return convertView;
    }

    /*存放控件 的ViewHolder*/
    public final class ViewHolder {
        public TextView daishu;
        public TextView nick;
        public TextView jingyin;
    }
}
